﻿

namespace Mulala.Cavan.Domain.MainBoundedContext.CorporationModule
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Linq;
    using System.Text;
    using FluentValidation.Attributes;
    using Mulala.Cavan.Core.Extension;
    using Mulala.Cavan.Domain.MainBoundedContext.AttachmentModule;
    using Mulala.Cavan.Domain.MainBoundedContext.ChargeModule;
    using Mulala.Cavan.Domain.MainBoundedContext.ConsignModule;
    using Mulala.Cavan.Domain.MainBoundedContext.DictionaryModule;
    using Mulala.Cavan.Domain.MainBoundedContext.InformationModule;
    using Mulala.Cavan.Domain.MainBoundedContext.NannyModule;
    using Mulala.Cavan.Domain.MainBoundedContext.SecurityModule;
    using Mulala.Cavan.Domain.MainBoundedContext.Setting;
    using Mulala.Cavan.Domain.Seedwork;
    using System.ComponentModel.DataAnnotations;

    [Serializable]
    [Validator(typeof(CorporationValidator))]
    public class Corporation : Persistent
    {
        [DisplayName("公司名称")]
        public virtual string FullName { get; set; }
        /// <summary>
        /// 用户帐户
        /// </summary>
        public virtual UserAccount UserAccount { get; set; }
        [DisplayName("地区")]
        public virtual Area Area { get; set; }
        [DisplayName("工商注册时间")]
        [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "yyyy-MM-dd")]  
        public virtual DateTime RegistrationTime { get; set; }
        [DisplayName("公司类型")]
        public virtual CorporationIdentifier.CorporationType Type { get; set; }
        [DisplayName("公司性质")]
        public virtual int Nature { get; set; }
        [DisplayName("经营年限")]
        public virtual int BusinessExperience { get; set; }
        [DisplayName("公司规模")]
        public virtual int Scale { get; set; }
        [DisplayName("服务项目")]
        public virtual long Speciality { get; set; }
        [DisplayName("联系人")]
        public virtual string Contact { get; set; }
        [DisplayName("联系Email")]
        public virtual string ContactEmail { get; set; }
        [DisplayName("公司地址")]
        public virtual string Address { get; set; }
        [DisplayName("手机")]
        public virtual string Telephone { get; set; }
        [DisplayName("固定电话")]
        public virtual string Mobile { get; set; }
        [DisplayName("传真")]
        public virtual string Fax { get; set; }
        [DisplayName("公司介绍")]
        public virtual string Introduce { get; set; }
        [DisplayName("公司文化")]
        public virtual string Culture { get; set; }
        [DisplayName("注册资金")]
        public virtual string Capital { get; set; }
        [DisplayName("收费说明")]
        public virtual string ChargeDescription { get; set; }
        [DisplayName("公司主页")]
        public virtual string HomePage { get; set; }
        [DisplayName("营业执照")]
        public virtual string BusinessLicence { get; set; }
        [DisplayName("在线客服")]
        public virtual string CustomService { get; set; }
        public virtual int SatisfactoryTotal { get; set; }
        public virtual int CommentTotal { get; set; }
        public virtual int ViewTotal { get; set; }
        public virtual int SearchTotal { get; set; }
        public virtual bool IsDeleted { get; set; }
        public virtual CorporationStatus CorporationStatus { get; set; }
        public virtual IList<Nanny> Nannies { get; set; }
        public virtual IList<ConsignBidder> ConsignBidders { get; set; }
        public virtual IList<CorporationComment> Comments { get; set; }
        public virtual IList<CorporationNew> News { get; set; }
        public virtual IList<Attachment> Attachments { get; set; }

        public override string ToDisplay()
        {
            return FullName;
        }

        public virtual BoolGenericResult<Corporation> ModifyInfo(
                                                    string fullName,
                                                    Area area,
                                                    DateTime registrationTime,
                                                    CorporationIdentifier.CorporationType type,
                                                    int nature,
                                                    int businessExperience,
                                                    int scale,
                                                    long speciality,
                                                    string contact,
                                                    string contactEmail,
                                                    string address,
                                                    string telephone,
                                                    string mobile,
                                                    string fax,
                                                    string introduce,
                                                    string culture,
                                                    string capital,
                                                    string chargeDescription,
                                                    string homePage,
                                                    string businessLicence,
                                                    string customService)
        {
            if (area == null)
            {
                throw new ArgumentException("");
            }

            BoolGenericResult<Corporation> result = new BoolGenericResult<Corporation>();
            this.FullName = fullName;
            this.Area = area;
            this.RegistrationTime = registrationTime;
            this.Type = type;
            this.Nature = nature;
            this.BusinessExperience = businessExperience;
            this.Scale = scale;
            this.Speciality = speciality;
            this.Contact = contact;
            this.ContactEmail = contactEmail;
            this.Address = address;
            this.Telephone = telephone;
            this.Mobile = mobile;
            this.Fax = fax;
            this.Introduce = introduce;
            this.Culture = culture;
            this.Capital = capital;
            this.ChargeDescription = chargeDescription;
            this.HomePage = homePage;
            this.BusinessLicence = businessLicence;
            this.CustomService = customService;

            this.CorporationStatus.BasicInfoStatus = CorporationIdentifier.CheckedStatus.Modified;

            result.Object = this;

            return result;
        }

        public virtual DeleteNannyResult DeleteNanny(Nanny deletedNanny)
        {
            if (deletedNanny == null)
            {
                throw new ArgumentException("");
            }

            DeleteNannyResult result = new DeleteNannyResult();

            deletedNanny.NannyStatus.OnLineStatus = NannyIdentifier.OnLineStatus.NeverOnLine;
            foreach (Consign c in deletedNanny.Consigns)
            {
                ConsignBidder consignbidder = c.ConsignBidders.FirstOrDefault(cb => cb.Bidder.ID == deletedNanny.ID);
                if (null != consignbidder)
                {
                    consignbidder.ConsignBidderStatus = ConsignIdentifier.ConsignBidderStatus.IsDeleted;
                    result.DeletedConsignBidders.Add(consignbidder);
                }
            }
            result.Object = deletedNanny;

            return result;
        }

        public virtual BoolGenericResult<Attachment> ModifyLogo(
                                                    string fileUrl,
                                                    string fileName)
        {
            BoolGenericResult<Attachment> result = new BoolGenericResult<Attachment>();
            Attachment logo = this.Attachments.FirstOrDefault(a => a.OwnerID == this.ID && a.AttachmentGroup == AttachmentIdentifier.AttachmentGroup.CorporationLogo);
            logo.FileUrl = fileUrl;
            logo.FileName = fileName;
            result.Object = logo;

            return result;
        }

        public virtual BoolGenericResult<Attachment> UploadPhoto(
                                                    string fileUrl,
                                                    string fileName)
        {
            BoolGenericResult<Attachment> result = new BoolGenericResult<Attachment>();
            if ((this.Attachments.Count + 1) > Project.Settings.CorporationPhotoMaxAmount)
            {
                result.IsSuccess = false;
                result.Messages.Add("公司风采照已达最大数，不予再上传");
            }

            Attachment photo = AttachmentFactory.CreateAttachment(AttachmentIdentifier.AttachmentGroup.CorporationPhoto, this.ID, fileName, fileUrl, true, AttachmentIdentifier.CheckedStatus.UnChecked,
                    false, 1, DateTime.Now, this.UserAccount.Name);

            result.Object = photo;

            return result;
        }

        public virtual BoolGenericResult<Attachment> UploadCertification(
                                                    string fileUrl,
                                                    string fileName)
        {
            BoolGenericResult<Attachment> result = new BoolGenericResult<Attachment>();

            Attachment certification = AttachmentFactory.CreateAttachment(AttachmentIdentifier.AttachmentGroup.CorporationCertification, this.ID, fileName, fileUrl, true, AttachmentIdentifier.CheckedStatus.UnChecked,
                    false, 1, DateTime.Now, this.UserAccount.Name);

            result.Object = certification;

            return result;
        }

        public virtual BoolGenericResult<Attachment> ModifyCertification(
                                                    int certificationID,
                                                    string fileUrl,
                                                    string fileName)
        {
            BoolGenericResult<Attachment> result = new BoolGenericResult<Attachment>();
            Attachment certification = this.Attachments.FirstOrDefault(a => a.ID == certificationID && a.AttachmentGroup == AttachmentIdentifier.AttachmentGroup.CorporationCertification);
            certification.FileUrl = fileUrl;
            certification.FileName = fileName;

            result.Object = certification;

            return result;
        }

        public virtual BoolGenericResult<Attachment> ModifyPhoto(
                                                    int photoID,
                                                    string fileUrl,
                                                    string fileName)
        {
            BoolGenericResult<Attachment> result = new BoolGenericResult<Attachment>();
            Attachment photo = this.Attachments.FirstOrDefault(a => a.ID == photoID && a.AttachmentGroup == AttachmentIdentifier.AttachmentGroup.CorporationPhoto);
            photo.FileUrl = fileUrl;
            photo.FileName = fileName;

            result.Object = photo;

            return result;
        }

        public virtual BoolGenericResult<Nanny> AddNanny(
                                UserAccount userAccount,
                                string name,
                                int age,
                                NannyIdentifier.Sex sex,
                                int nation,
                                DateTime birthday,
                                string telephone,
                                string mobile,
                                string qq,
                                string msn,
                                bool isContactCompany,
                                int astrology,
                                int computerLevel,
                                int chineseZodiac,
                                bool isMarried,
                                long language,
                                Area area,
                                string address,
                                int degree,
                                bool canDrive,
                                bool hasChildren,
                                int healthy,
                                int faith,
                                long mainSkill,
                                long firstSkill,
                                long secondSkill,
                                long thirdSkill,
                                bool isTrained,
                                int experience,
                                int salary,
                                string introduce,
                                long certificate,
                                string declaration,
                                NannyIdentifier.NannyType type,
                                bool isWorking,
                                bool isNeedAccommodate,
                                bool isNeedMeal)
        {
            BoolGenericResult<Nanny> result = new BoolGenericResult<Nanny>();

            NannyStatus nannyStatus = NannyStatusFactory.CreateNannyStatus(this.UserAccount.Name);
            Nanny nanny = NannyFactory.CreateNanny(this, userAccount, name, age, sex, nation, birthday, telephone, mobile, qq, msn, isContactCompany,
                astrology, computerLevel, chineseZodiac, isMarried, language, area, address, degree, canDrive, hasChildren, healthy, faith, mainSkill,
                firstSkill, secondSkill, thirdSkill, isTrained, experience, salary, introduce, certificate, declaration, type, isWorking, isNeedAccommodate, isNeedMeal,
                0, 0, 0, 0, false, nannyStatus, null, null, null, DateTime.Now, this.UserAccount.Name);

            result.Object = nanny;

            return result;
        }

        public virtual BoolGenericResult<Nanny> PublishNanny(
                                                    Nanny nanny)
        {
            if (nanny == null)
            {
                throw new ArgumentException("");
            }

            BoolGenericResult<Nanny> result = new BoolGenericResult<Nanny>();
            if (!Project.Settings.IsFree)
            {
                if (this.Nannies.Count(n => n.NannyStatus.OnLineStatus == NannyIdentifier.OnLineStatus.OnLine) >= this.UserAccount.UserServices[0].NannyMax)
                {
                    result.IsSuccess = false;
                    result.Messages.Add("发布的家政人员数量已达上限，不与再发布！");
                    return result;
                }
            }
            if (nanny.NannyStatus.CheckedStatus != NannyIdentifier.CheckedStatus.Passed)
            {
                result.IsSuccess = false;
                result.Messages.Add("此家政人员还未通过审核，不与上线！");
                return result;
            }
            nanny.NannyStatus.OnLineStatus = NannyIdentifier.OnLineStatus.OnLine;
            result.Object = nanny;

            return result;
        }

        public virtual BoolGenericResult<Nanny> UnderNanny(
                                                    Nanny nanny)
        {
            if (nanny == null)
            {
                throw new ArgumentException("");
            }

            BoolGenericResult<Nanny> result = new BoolGenericResult<Nanny>();
            nanny.NannyStatus.OnLineStatus = NannyIdentifier.OnLineStatus.OffLine;
            result.Object = nanny;

            return result;
        }

        public virtual BoolGenericResult<ConsignBidder> BidConsign(
                                                            Nanny nanny,
                                                            Consign consign)
        {
            if (nanny == null)
            {
                throw new ArgumentException("");
            }

            if (consign == null)
            {
                throw new ArgumentException("");
            }

            BoolGenericResult<ConsignBidder> result = new BoolGenericResult<ConsignBidder>();
            if (nanny.NannyStatus.BidStatus == NannyIdentifier.BidStatus.CannotBid)
            {
                result.IsSuccess = false;
                result.Messages.Add("此家政人员当前为禁止竞标状态，请先更新为可竞标！");
                return result;
            }
            ConsignBidder consignBidder = ConsignBidderFactory.CreateConsignBidder(consign, nanny, this, ConsignIdentifier.ConsignBidderStatus.IsNew, false, DateTime.Now,
                this.UserAccount.Name);
            result.Object = consignBidder;

            return result;
        }

        public virtual BoolGenericResult<ConsignBidder> CancelConsign(
                                                            Nanny nanny,
                                                            Consign consign)
        {
            if (nanny == null)
            {
                throw new ArgumentException("");
            }

            if (consign == null)
            {
                throw new ArgumentException("");
            }

            BoolGenericResult<ConsignBidder> result = new BoolGenericResult<ConsignBidder>();
            if (consign.ConsignStatus == ConsignIdentifier.ConsignStatus.IsBidding ||
                consign.ConsignStatus == ConsignIdentifier.ConsignStatus.IsLocked)
            {
                ConsignBidder consignBidder = consign.ConsignBidders.FirstOrDefault(cb => cb.Bidder.ID == nanny.ID);
                consignBidder.ConsignBidderStatus = ConsignIdentifier.ConsignBidderStatus.IsCanceled;
                consign.BidCount = consign.BidCount - 1;
            }

            return result;
        }

        public virtual BoolGenericResult<CorporationNew> PublishNew(
                                                            string title,
                                                            string content,
                                                            CorporationIdentifier.NewsType type)
        {
            BoolGenericResult<CorporationNew> result = new BoolGenericResult<CorporationNew>();

            CorporationNew corporationNew = CorporationNewFactory.CreateCorporationNew(this, title, content, type, Project.Settings.DefaultCorporationNewViewTotal, CorporationIdentifier.NewStatus.OnShow, DateTime.Now, this.UserAccount.Name);
            result.Object = corporationNew;

            return result;
        }

        public virtual BoolGenericResult<CorporationNew> ModifyNew(
                                                            CorporationNew changedCorporationNew,
                                                            string title,
                                                            string content,
                                                            CorporationIdentifier.NewsType type)
        {
            BoolGenericResult<CorporationNew> result = new BoolGenericResult<CorporationNew>();

            changedCorporationNew.Title = title;
            changedCorporationNew.Content = content;
            changedCorporationNew.Type = type;

            result.Object = changedCorporationNew;

            return result;
        }

        public virtual BoolGenericResult<CorporationNew> DeleteNew(CorporationNew corporationNew)
        {
            if (corporationNew == null)
            {
                throw new ArgumentException("");
            }

            BoolGenericResult<CorporationNew> result = new BoolGenericResult<CorporationNew>();

            corporationNew.NewStatus = CorporationIdentifier.NewStatus.Deleted;
            result.Object = corporationNew;

            return result;
        }

        public virtual BoolGenericResult<Corporation> SubscribeUserService(UserService userService)
        {
            if (userService == null)
            {
                throw new ArgumentException("");
            }

            BoolGenericResult<Corporation> result = new BoolGenericResult<Corporation>();

            if (this.UserAccount.CreditLimit < userService.Price)
            {
                result.IsSuccess = false;
                result.Messages.Add("余额不足，不能订购");
                return result;
            }

            this.UserAccount.CreditLimit = this.UserAccount.CreditLimit - userService.Price;
            this.CorporationStatus.NannyRecommendLeftMonth = this.CorporationStatus.NannyRecommendLeftMonth + userService.NannyRecommendTotalMonth;
            this.CorporationStatus.NannyVipLeftMonth = this.CorporationStatus.NannyVipLeftMonth + userService.NannyVipTotalMonth;
            this.CorporationStatus.CorporationVipLeftMonth = this.CorporationStatus.CorporationVipLeftMonth + userService.CorporationVipTotalMonth;

            this.UserAccount.UserServices.Add(userService);

            result.Object = this;

            return result;
        }

        public virtual BoolGenericResult<CorporationStatus> RefreshSelf()
        {
            BoolGenericResult<CorporationStatus> result = new BoolGenericResult<CorporationStatus>();

            if (this.CorporationStatus.RefreshTime.Day != DateTime.Now.Day &&
                this.CorporationStatus.RefreshTime.Month != DateTime.Now.Month &&
                this.CorporationStatus.RefreshTime.Year != DateTime.Now.Year)
            {
                this.CorporationStatus.RefreshCount = 0;
            }

            if (!Project.Settings.IsFree)
            {
                if (this.UserAccount.UserServices.IsNull())
                {
                    result.IsSuccess = false;
                    result.Messages.Add("没有刷新服务，不与刷新！");
                    return result;
                }
                if (this.CorporationStatus.RefreshCount >= this.UserAccount.UserServices[0].RefreshPerDay)
                {
                    result.IsSuccess = false;
                    result.Messages.Add("刷新的次数已达上限，不与再刷新！");
                    return result;
                }
            }

            this.CorporationStatus.RefreshTime = DateTime.Now;
            this.CorporationStatus.RefreshCount = this.CorporationStatus.RefreshCount + 1;

            result.Object = this.CorporationStatus;

            return result;
        }

        public virtual BoolGenericResult<NannyStatus> RecommendNanny(Nanny nanny)
        {
            if (nanny == null)
            {
                throw new ArgumentException("");
            }

            BoolGenericResult<NannyStatus> result = new BoolGenericResult<NannyStatus>();
            if (!Project.Settings.IsFree)
            {
                if (this.Nannies.Count(n => n.NannyStatus.RecommendTimeout > DateTime.Now) >= this.UserAccount.UserServices[0].RecommendNannyMax)
                {
                    result.IsSuccess = false;
                    result.Messages.Add("推荐的家政人员数量已达上限，不与再推荐！");
                    return result;
                }
            }
            nanny.NannyStatus.RecommendTime = DateTime.Now;
            nanny.NannyStatus.RecommendTimeout = DateTime.Now.AddMonths(Project.Settings.DefaultRecommendDuration);

            result.Object = nanny.NannyStatus;

            return result;
        }

        public virtual BoolGenericResult<NannyStatus> RefreshNanny(Nanny nanny)
        {
            if (nanny == null)
            {
                throw new ArgumentException("");
            }

            BoolGenericResult<NannyStatus> result = new BoolGenericResult<NannyStatus>();
            if (!Project.Settings.IsFree)
            {
                if (nanny.NannyStatus.RefreshCount >= this.UserAccount.UserServices[0].RefreshPerDay)
                {
                    result.IsSuccess = false;
                    result.Messages.Add("刷新的此说已达上限，不与再刷新！");
                    return result;
                }
            }
            if (nanny.NannyStatus.RefreshTime.Day != DateTime.Now.Day &&
                nanny.NannyStatus.RefreshTime.Month != DateTime.Now.Month &&
                nanny.NannyStatus.RefreshTime.Year != DateTime.Now.Year)
            {
                nanny.NannyStatus.RefreshCount = 0;
            }
            nanny.NannyStatus.RefreshTime = DateTime.Now;
            nanny.NannyStatus.RefreshCount = nanny.NannyStatus.RefreshCount + 1;

            result.Object = nanny.NannyStatus;

            return result;
        }

        public virtual BoolGenericResult<NannyStatus> SetNannyToVip(Nanny nanny, int vipValidMonth)
        {
            if (nanny == null)
            {
                throw new ArgumentException("");
            }

            BoolGenericResult<NannyStatus> result = new BoolGenericResult<NannyStatus>();
            if (Project.Settings.IsFree)
            {
                result.IsSuccess = false;
                result.Messages.Add("系统处于免费阶段，不与设置VIP！");
                return result;
            }

            if (this.CorporationStatus.NannyVipLeftMonth > vipValidMonth)
            {
                if (nanny.NannyStatus.VIPTimeout < DateTime.Now)
                {
                    nanny.NannyStatus.VIPTimeout = DateTime.Now.AddMonths(vipValidMonth);
                }
                else
                {
                    nanny.NannyStatus.VIPTimeout = nanny.NannyStatus.VIPTimeout.AddMonths(vipValidMonth);
                }

                this.CorporationStatus.NannyVipLeftMonth = this.CorporationStatus.NannyVipLeftMonth - vipValidMonth;
            }

            result.Object = nanny.NannyStatus;

            return result;
        }

        public virtual BoolGenericResult<NannyStatus> SetNannyToUnVip(Nanny nanny)
        {
            if (nanny == null)
            {
                throw new ArgumentException("");
            }

            BoolGenericResult<NannyStatus> result = new BoolGenericResult<NannyStatus>();
            if (Project.Settings.IsFree)
            {
                result.IsSuccess = false;
                result.Messages.Add("系统处于免费阶段，不与设置VIP！");
                return result;
            }

            TimeSpan ts = nanny.NannyStatus.VIPTimeout.Subtract(DateTime.Now).Duration();

            this.CorporationStatus.NannyVipLeftMonth = this.CorporationStatus.NannyVipLeftMonth + (ts.Days / 30);
            nanny.NannyStatus.VIPTimeout = DateTime.Now;

            result.Object = nanny.NannyStatus;


            return result;
        }

        public virtual BoolGenericResult<NannyStatus> SetNannyToOnline(Nanny nanny)
        {
            if (nanny == null)
            {
                throw new ArgumentException("");
            }

            BoolGenericResult<NannyStatus> result = new BoolGenericResult<NannyStatus>();

            if (this.GetMyOnlineNannyMax() > this.GetMyOnlineNannyTotal())
            {
                nanny.NannyStatus.OnLineStatus = NannyIdentifier.OnLineStatus.OnLine;
            }
            else
            {
                result.IsSuccess = false;
                result.Messages.Add("上线家政人员已达最大数，不与再上线！");
                return result;
            }

            result.Object = nanny.NannyStatus;

            return result;
        }

        public virtual BoolGenericResult<NannyStatus> SetNannyToOffline(Nanny nanny)
        {
            if (nanny == null)
            {
                throw new ArgumentException("");
            }

            BoolGenericResult<NannyStatus> result = new BoolGenericResult<NannyStatus>();

            nanny.NannyStatus.OnLineStatus = NannyIdentifier.OnLineStatus.OffLine;

            result.Object = nanny.NannyStatus;

            return result;
        }

        public virtual BoolGenericResult<NannyStatus> SetNannyToCanBid(Nanny nanny)
        {
            if (nanny == null)
            {
                throw new ArgumentException("");
            }

            BoolGenericResult<NannyStatus> result = new BoolGenericResult<NannyStatus>();

            nanny.NannyStatus.BidStatus = NannyIdentifier.BidStatus.CanBid;

            result.Object = nanny.NannyStatus;

            return result;
        }

        public virtual BoolGenericResult<NannyStatus> SetNannyToCannotBid(Nanny nanny)
        {
            if (nanny == null)
            {
                throw new ArgumentException("");
            }

            BoolGenericResult<NannyStatus> result = new BoolGenericResult<NannyStatus>();

            nanny.NannyStatus.BidStatus = NannyIdentifier.BidStatus.CannotBid;

            result.Object = nanny.NannyStatus;

            return result;
        }

        public virtual BoolGenericResult<NannyStatus> SetNannyToRecommend(Nanny nanny, int recommendValidMonth)
        {
            if (nanny == null)
            {
                throw new ArgumentException("");
            }

            BoolGenericResult<NannyStatus> result = new BoolGenericResult<NannyStatus>();

            if (this.CorporationStatus.NannyRecommendLeftMonth > recommendValidMonth)
            {
                if (nanny.NannyStatus.RecommendTimeout < DateTime.Now)
                {
                    nanny.NannyStatus.RecommendTimeout = DateTime.Now.AddMonths(recommendValidMonth);
                }
                else
                {
                    nanny.NannyStatus.RecommendTimeout = nanny.NannyStatus.RecommendTimeout.AddMonths(recommendValidMonth);
                }

                this.CorporationStatus.NannyRecommendLeftMonth = this.CorporationStatus.NannyRecommendLeftMonth - recommendValidMonth;
            }
            else
            {
                result.IsSuccess = false;
                result.Messages.Add("可够推荐家政人员的月份数已不够，不与推荐！");
                return result;
            }

            result.Object = nanny.NannyStatus;

            return result;
        }

        public virtual BoolGenericResult<NannyStatus> SetNannyToUnRecommend(Nanny nanny)
        {
            if (nanny == null)
            {
                throw new ArgumentException("");
            }

            BoolGenericResult<NannyStatus> result = new BoolGenericResult<NannyStatus>();

            TimeSpan ts = nanny.NannyStatus.RecommendTimeout.Subtract(DateTime.Now).Duration();

            this.CorporationStatus.NannyRecommendLeftMonth = this.CorporationStatus.NannyRecommendLeftMonth + (ts.Days / 30);
            nanny.NannyStatus.RecommendTimeout = DateTime.Now;

            result.Object = nanny.NannyStatus;

            return result;
        }

        public virtual BoolGenericResult<UserMessage> LeaveMessage(
                                                            UserAccount ownerUserAccount,
                                                            string content)
        {
            if (ownerUserAccount == null)
            {
                throw new ArgumentException("");
            }

            BoolGenericResult<UserMessage> result = new BoolGenericResult<UserMessage>();
            UserMessage userMessage = UserMessageFactory.CreateUserMessage(ownerUserAccount, content, 0, 0, this.UserAccount, false, DateTime.Now, this.UserAccount.Name);

            result.Object = userMessage;

            return result;
        }

        public virtual BoolGenericResult<UserMessage> ReplyMessage(UserMessage userMessage, string content)
        {
            if (userMessage == null)
            {
                throw new ArgumentException("");
            }

            BoolGenericResult<UserMessage> result = new BoolGenericResult<UserMessage>();
            UserMessage repliedMessage = UserMessageFactory.CreateUserMessage(this.UserAccount, content, userMessage.ID, 0, this.UserAccount, false, DateTime.Now, this.UserAccount.Name);
            result.Object = repliedMessage;
            userMessage.Reply = userMessage.Reply + 1;

            return result;
        }

        public virtual BoolGenericResult<Note> SendNote(
                                            string title,
                                            string content,
                                            InformationIdentifier.NoteType type,
                                            IList<NoteReceiver> noteReceivers)
        {
            if (noteReceivers == null)
            {
                throw new ArgumentException("");
            }

            BoolGenericResult<Note> result = new BoolGenericResult<Note>();

            Note note = NoteFactory.CreateNote(title, content, type, this.UserAccount, false, noteReceivers, this.UserAccount.Name);
            result.Object = note;

            return result;
        }

        public virtual int GetMyNannyVipTotalMonth()
        {
            int vipTotalMonth = 0;
            foreach (UserService us in this.UserAccount.UserServices)
            {
                vipTotalMonth = vipTotalMonth + us.NannyVipTotalMonth;
            }

            return vipTotalMonth;
        }

        public virtual int GetMyOnlineNannyMax()
        {
            int onlineMax = 0;
            foreach (UserService us in this.UserAccount.UserServices)
            {
                onlineMax = onlineMax + us.NannyMax;
            }

            return onlineMax;
        }

        public virtual int GetMyOnlineNannyTotal()
        {
            int onlineTotalMonth = 0;

            onlineTotalMonth = this.Nannies.Count(n => n.NannyStatus.OnLineStatus.GetHashCode() == NannyIdentifier.OnLineStatus.OnLine.GetHashCode());

            return onlineTotalMonth;
        }

        public virtual int GetMyRecommendNannyTotal()
        {
            int recommendTotalMonth = 0;

            recommendTotalMonth = this.Nannies.Count(n => n.NannyStatus.RecommendTimeout > DateTime.Now);

            return recommendTotalMonth;
        }
    }
}
